//
//  ECModelData.m
//  Edu_iOS
//
//  Created by yanyan on 2017/9/8.
//  Copyright © 2017年 yanyan. All rights reserved.
//

#import "ECModelData.h"
#import "CourseModel.h"
#import "ECCourseOrderModel.h"
@implementation ECModelData
+ (id)arrayForCategory:(id)jsonData
{
    NSMutableArray *categoryData = [NSMutableArray array];
    NSArray *data = [jsonData valueForKey:@"data"];
    if (data.count > 0) {
        PrimaryCategoryModel *mo = [[PrimaryCategoryModel alloc]init];
        mo.title = @"全部";
        mo.modelId = nil;
        mo.subCategoryArray = [NSMutableArray array];
        [categoryData addObject:mo];
    }
    for (id obj in data) {
        PrimaryCategoryModel *mo = [[PrimaryCategoryModel alloc]initWithObject:obj];
        [categoryData addObject:mo];
    }
    return categoryData;
}
+ (id)arrayForAllCategory:(id)jsonData{
    NSMutableArray *categoryData = [NSMutableArray array];
    NSArray *data = [jsonData valueForKey:@"data"];
    for (id obj in data) {
        PrimaryCategoryModel *mo = [[PrimaryCategoryModel alloc]initWithObject:obj];
        [categoryData addObject:mo];
    }
    return categoryData;
}
// 课程列表 首页& 搜索，课程列表
+ (id)arrayForCourses:(id)jsonData{
    NSMutableArray *coursesData = [NSMutableArray array];
//    NSArray *data = [[jsonData valueForKey:@"data"] valueForKey:@"resources"];
  
    for (id obj in jsonData) {
        CourseModel *mo = [[CourseModel alloc]initWithObject:obj];
        
        [coursesData addObject:mo];
    }
  return coursesData;
}
+ (id)arrayForAddCategory:(id)obj
{
    NSArray *titleArr = @[@"学前教育",@"小学教育",@"初中教育",@"高中教育", @"大学教育"];
    
    NSMutableArray *subCategorys = [NSMutableArray array];
    for (int i = 0; i < titleArr.count; i++) {
        PrimaryCategoryModel *mo = [[PrimaryCategoryModel alloc]init];
        mo.modelId = [NSString stringWithFormat:@"%d",i];
        NSMutableArray *subArray = [NSMutableArray arrayWithCapacity:2];
        NSArray *subTitleArr = @[@"语文",@"数学",@"英语",@"道德与法治", @"历史",@"地理",@"生物",@"物理",@"化学",@"全科辅导"];
        for (int i = 0 ; i < subTitleArr.count; i ++) {
            PrimaryCategoryModel *mo1 = [[PrimaryCategoryModel alloc]init];
            mo1.modelId = [NSString stringWithFormat:@"%ld",[mo.modelId integerValue] * 1000 + 100 + i];
            mo1.title = subTitleArr[i];
            [subArray addObject:mo1];
        }
        mo.subCategoryArray = subArray;

        [subCategorys addObject:mo];
    }

    
    return subCategorys;
}
+ (id)arrayForSubCategoryData:(id)obj
{
    NSArray *titleArr = @[@"语文",@"数学",@"英语",@"道德与法治", @"历史",@"地理",@"生物",@"物理",@"化学",@"全科辅导"];
//    @"其他",@"",@""
    //  如果 子分类<=6个,那么直接展示。如果>6个，那么显示前五个 + 一个更多（包含剩下的信息）。
    NSMutableArray *subCategorys = [NSMutableArray array];
    if (titleArr.count <= 6) {
        for (int i = 0 ; i < titleArr.count; i ++) {
            SubCategoryModel *mo = [[SubCategoryModel alloc]init];
            mo.title = titleArr[i];
            mo.folderStyle = CategoryCellStyleNone;
            [subCategorys addObject:mo];
        }
    } else {
        SubCategoryModel *mo_more = [[SubCategoryModel alloc]init];
        mo_more.title = @"更多";
        mo_more.folderStyle = CategoryCellStyleFolded;
        NSMutableArray *arr_more = [NSMutableArray array];
        for (int i = 0 ; i < titleArr.count ; i ++) {
            SubCategoryModel *mo = [[SubCategoryModel alloc]init];
            mo.title = titleArr[i];
            mo.folderStyle = CategoryCellStyleNone;
            if (i < 5) {
                [subCategorys addObject:mo];
            } else {
                [arr_more addObject:mo];
            }
        }
        mo_more.modelArr = arr_more;
        [subCategorys addObject:mo_more];

    }
    
    
    return subCategorys;
}
+ (id)arrayForOrderData:(id)obj
{
    NSArray *titleArr = @[@"综合排序",@"人气排序",@"价格由低到高",@"价格由高到低"];
    NSMutableArray *orderArr = [NSMutableArray array];
    for (NSString *str in titleArr) {
        PrimaryCategoryModel *mo = [[PrimaryCategoryModel alloc]init];
        mo.title = str;
        mo.selected = NO;
        [orderArr addObject:mo];
    }
    return orderArr;
}
//返回折叠的数据
+ (id)arrayForFoldSubCategorys:(NSMutableArray *)categorys
{
    SubCategoryModel *mo = [categorys objectAtIndex:categorys.count - 1];
    mo.title = @"更多";
    mo.folderStyle = CategoryCellStyleFolded;
    [categorys removeObjectsInRange:NSMakeRange(5, mo.modelArr.count)];
    
    return categorys;
}

+(id)arrayForUnfoldSubCategorys:(NSMutableArray *)categorys
{
    SubCategoryModel *mo = [categorys objectAtIndex:5];
    mo.title = @"收起";
    mo.folderStyle = CategoryCellStyleUnfolded;
    [categorys insertObjects:mo.modelArr atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(5, mo.modelArr.count)]];
    NSLog(@"categorys - %@",categorys);
    return categorys;
}
+ (id)arrayForCategoryOrderList:(id)data{
    NSMutableArray *arr = [NSMutableArray array];
    for (id obj in data) {
        ECCourseOrderModel *mo = [[ECCourseOrderModel alloc]initWithObject:obj];
        [arr addObject:mo];
    }
    return arr;
}

@end
